/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBeans;

import controladores.ConfirmarCheckInCont;
import controladores.ConsultarReservaCont;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import org.apache.log4j.Logger;
import org.primefaces.component.datatable.DataTable;
import org.primefaces.component.inputtext.InputText;

/**
 *
 * @author ricardo
 */
@ManagedBean
@ViewScoped
public class CheckInSala implements Serializable {

    private DataTable tablaReservasCheckables;
    protected Logger log = Logger.getLogger(CheckInSala.class);
    
    /** Creates a new instance of CheckInSala */
    public CheckInSala() {
    }

    public DataTable getTablaReservasCheckables() {
        return tablaReservasCheckables;
    }

    public void setTablaReservasCheckables(DataTable tablaReservasCheckables) {
        this.tablaReservasCheckables = tablaReservasCheckables;
    }

    
    public List<modelos.pojos.ReservaSala> listarReservasCheckables(){
        FacesContext facesContext = FacesContext.getCurrentInstance();
        UIViewRoot root = facesContext.getViewRoot();
        InputText caja = (InputText) root.findComponent("este").findComponent("codReserva");
        String codigoIngresado = caja.getValue() + "";
        return ConsultarReservaCont.consultarReservasSalasCheckables(codigoIngresado, new Date());
    }
    
    public void registrarCheckIn(){
        modelos.pojos.ReservaSala seleccion = (modelos.pojos.ReservaSala) tablaReservasCheckables.getRowData();
        ConfirmarCheckInCont.confirmarCheckInReservaSala(seleccion.getReserva().getCodigoReserva(), seleccion.getSala().getNumero(), UserSession.cedulaRegistrante);
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage("Check-In Registrado!"));
    }
    
}
